/********************************************/
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				CompanyNameOptions.java
  //    Title   :			get the Company Data into a list box
  //	FUNCTION:
  //	BY:					Jet Tao
  //	DATE:				09/12/2003
  // --------------------------------------------------------------
/*********************************************/

package tss.options;

import java.sql.Connection;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import tss.common.Options2;
import tss.company.CompanyBean;
import tss.company.CompanyProcess;

public class CompanyNameOptions
     extends Options2
{
	private Logger logger = Logger.getLogger(CompanyNameOptions.class);
  public CompanyNameOptions() {
    this.load();
  }


  @Override
protected ArrayList createOptions(Connection con)
    throws Exception
  {
      ArrayList options = new ArrayList();
      CompanyBean Company = CompanyProcess.createBean();
      Company.setCompany_code("");
      CompanyBean[] Companys = CompanyProcess.find(con,Company);
      for (int i=0; i<Companys.length; i++)
      {
          Options2.Option option
          = new Options2.Option( Companys[i].getCompany_code(),
                                Companys[i].getCompany_name());
          options.add(i,option);
      }

      return options;
  }

  /**
   * Get a Company Name By Company 
   * @param
   *       pCompany                company 
   */
  public String getCompanyName(String pCompany) {
    String strCompanyName = ""; //CompanyNameName
    Options2.Option objOption; //New A Temp Option Object

    try {
      //if exist records
      if (this.options != null) {
        objOption = new Options2.Option();
        for (int I = 0; I < this.options.size(); I++) {
          //Get A Company record include Company and Companyname
          objOption = (Options2.Option)this.options.get(I);
          if (pCompany.equalsIgnoreCase(objOption.getValue())) {
            strCompanyName = objOption.getDescription();
            return strCompanyName;
          }
        }
      }
    }
    catch (Exception ex) {
      logger.error("CompanyNameOptions:getCompanyName  " + ex.getMessage());
      strCompanyName = "";
    }
    finally {
      return strCompanyName;
    }
}

}